import * as contains  from './contains';
import axios from 'axios';
import { fromJS } from 'immutable';

export const ewmShow = () => ({
	type: contains.EWM_SHOW
});

export const homeData = (result) => ({
		type: contains.CHANGE_HOME_DATA,
			topicList: result.topicList,
			articleList: result.articleList,
			recommendList: result.recommendList,
			writerList: result.writerList
});

export const getHomeInfo = () => {
	return (dispatch) => {
		axios.get('/api/home.json').then((res) => {
			const result = res.data.data;
		dispatch(homeData(result));
		})
	}
}

export const getMoreData = (list, nextPage) =>({
	type: contains.GET_MORE_LIST,
	list: fromJS(list),
	nextPage
})

export const getMorelist = (page) => {
	return (dispatch) => {
		axios.get('/api/homeList.json?page=' + page).then((res) => {
			const result = res.data.data;
		dispatch(getMoreData(result, page+1));
		})
	}
}

export const getScroll = (show) => ({
	type: contains.GET_SCROLL,
	show
})